<?php
/**
 * Created by PhpStorm.
 * User: pwk
 * Date: 15-3-19
 * Time: 上午10:28
 */
// 远端服务器配置信息
include_once '../../common/func.inc.php';
include_once '../common/Db.class.php';
$dbConf = include '../common/db.conf.php';
\PFT\Db::Conf($dbConf['remote_1']);
$action = $_REQUEST['action'];
switch ($action) {
    case 'Create':
        $uplog_title    = safetxt($_POST['title']);
        $uplog_content  = safetxt($_POST['content']);
        //判断用户类型
       if($_SESSION['dtype']==9)
       {
            //取到更新标题、内容、操作ip、操作时间
            //拼出sql语句,执行sql操作
            $str="INSERT INTO pft_update_log (uplog_title,uplog_content,access_date) VALUES".
                " ('{$uplog_title}','{$uplog_content}',now())";
            try{
                $row = \PFT\Db::Connect()->exec($str);
                echo "成功提交" . $row ."条更新公告！";
            }
            catch(PDOException $e) {
                //失败
                echo "发布失败！" . $e->getMessage();
            }
        }
        echo "超出权限！";
        break;
        case 'Read':
        //拼出sql语句,执行sql操作
        $limit="0,100";
        $str ="select uplog_title,uplog_content from pft_update_log order by id desc limit {$limit}";
        $stmt = \PFT\Db::Connect()->prepare($str);
        $stmt->execute();
        $tmp = $stmt->fetchAll(PDO::FETCH_ASSOC);
        echo json_encode($tmp);
        break;

    default:
        echo "错误！";
        break;
}
?>

